home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / RWSUB.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  3KB  |  126 lines

  1. ; RWSUB - disk read/write subroutine for compiled BASIC
  2. ; Copyright 1983 Data Base Decisions
  3. ; CALL RWSUB(FIL$,FCB$,FUNC%,SBYTELO%,SBYTEHI%,NOBYTES%,DTASEG%,RETCODE%)
  4. ; FIL$ is the name of the file to be read or written
  5. ; FCB$ is a work area - allocate 40 spaces
  6. ; FUNC% indicates reading (0), writing (1), or creating & writing (2)
  7. ; SBYTELO% is the low part of the start byte
  8. ; SBYTEHI% is the high part of the start byte (HI*65536+LO)
  9. ; NOBYTES% is the number of bytes to be read/written
  10. ; DTASEG% is the segment to be read into or written from
  11. ; RETCODE% is an error return code
  12.  
  13. skip    equ 2            ; 2 for compiled, 1 for interpretive
  14.  
  15. cseg    segment para public 'code'
  16. public    rwsub
  17. rwsub    proc far
  18.     assume cs:cseg,ds:nothing,ss:nothing,es:nothing
  19.  
  20.     push bp
  21.     mov bp,sp
  22.  
  23.     push ds         ; save orig ds
  24.     mov si,[bp+8]        ; point to DTASEG%
  25.     mov ax,[si]
  26.     mov ds,ax        ; now in ds
  27.     xor dx,dx        ; clear dx
  28.     mov ah,1ah
  29.     int 21h         ; set dta
  30.     pop ds            ; back to orig ds
  31.  
  32.                 ; parse FIL$ into FCB$
  33.     mov si,[bp+20]        ; point to FIL$
  34.     add si,skip
  35.     mov si,[si]
  36.     mov di,[bp+18]        ; point to FCB$
  37.     add di,skip
  38.     mov di,[di]
  39.     mov ax,2901h
  40.     int 21h         ; parse file name
  41.     cmp al,0        ; error?
  42.     jz p005         ; no
  43.     mov ah,0        ; set parse error
  44.     jmp p030
  45.  
  46. p005:                ; open the file
  47.     mov si,[bp+18]        ; point to FCB$
  48.     add si,skip
  49.     mov dx,[si]        ; fcb address
  50.     mov si,[bp+16]        ; point to FUNC%
  51.     mov al,[si]        ; get access code in al
  52.     mov ah,16h
  53.     cmp al,2        ; create?
  54.     jz p010         ; yes
  55.     mov ah,0fh        ; normal open
  56.     mov cx,0        ; clear attributes
  57. p010:    int 21h         ; open the file
  58.     cmp al,0        ; error?
  59.     jz p015         ; no
  60.     mov ah,1        ; set open error
  61.     jmp p030
  62.  
  63. p015:                ; fix up the fcb
  64.     mov si,[bp+18]        ; point to FCB$
  65.     add si,skip
  66.     mov si,[si]
  67.     mov bx,14
  68.     add bx,si        ; point to record size
  69.     mov ax,1
  70.     mov [bx],ax        ; set record size
  71.     mov bx,32
  72.     add bx,si        ; point to current record
  73.     mov [bx],ah        ; zero it
  74.     inc bx
  75.     mov si,[bp+14]        ; point to SBYTELO%
  76.     mov ax,[si]        ; get the number
  77.     mov [bx],ax        ; and save in the fcb
  78.     inc bx
  79.     inc bx
  80.     mov si,[bp+12]        ; point to SBYTEHI%
  81.     mov ax,[si]        ; get the number
  82.     mov [bx],ax        ; and save in the fcb
  83.  
  84.                 ; read/write the file
  85.     mov si,[bp+18]        ; point to FCB$
  86.     add si,skip
  87.     mov dx,[si]        ; fcb address
  88.     mov si,[bp+10]        ; point to NOBYTES%
  89.     mov cx,[si]        ; number of bytes to read/write
  90.     mov si,[bp+16]        ; point to FUNC%
  91.     mov ah,[si]        ; 0 for read, 1 for write, 2 for create
  92.     cmp ah,2        ; create?
  93.     jnz p020        ; no
  94.     dec ah            ; yes - make it a write
  95. p020:    add ah,27h        ; setup interrupt function
  96.     int 21h         ; read/write the file
  97.     mov si,[bp+10]        ; point to NOBYTES%
  98.     mov [si],cx        ; save bytes read/written
  99.     push ax         ; save errors, if any
  100.  
  101.                 ; close the file
  102.     mov ah,10h
  103.     int 21h         ; close the file
  104.     cmp al,0        ; any errors?
  105.     jz p025         ; no
  106.     pop bx            ; restore ax into bx
  107.     mov ah,3        ; indicate close error
  108.     jmp p030
  109.  
  110. p025:    pop ax
  111.     cmp al,0        ; any read/write errors?
  112.     jz p040         ; no
  113.     mov ah,2        ; indicate error type
  114.  
  115. p030:                ; error handler
  116.     mov si,[bp+6]        ; point to RETCODE%
  117.     mov [si],ax        ; save the error
  118.  
  119. p040:                ; return to caller
  120.     pop bp
  121.     ret 16
  122.  
  123. rwsub    endp
  124. cseg    ends
  125.     end
  126.